/*
 *                  BioJava development code
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  If you do not have a copy,
 * see:
 *
 *      http://www.gnu.org/copyleft/lesser.html
 *
 * Copyright for this code is held jointly by the individual
 * authors.  These should be listed in @author doc comments.
 *
 * For more information on the BioJava project and its aims,
 * or to join the biojava-l mailing list, visit the home page
 * at:
 *
 *      http://www.biojava.org/
 * 
 * Created on Mar 23, 2007
 * 
 */

package org.biodas.jdas.dassources.utils;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import org.biodas.jdas.schema.sources.COORDINATES;


/** a speedup class to keep the coordinate systems in memory
 * 
 * @author Andreas Prlic
 *
 */
public class DasCoordinateSystemCollector {

	Map csmap;
	
	public DasCoordinateSystemCollector(){
		csmap = new HashMap(); 
	}
	
	public Set keySet(){
		return csmap.keySet();
	}
	public COORDINATES get(Object key){
		return (COORDINATES) csmap.get(key);
	}
	
	public void addCoordinateSystem(int coordNS_auto, COORDINATES dcs){
		csmap.put(new Integer(coordNS_auto), dcs);
		
	}
	
	/** returns the coordNS primary key for a coordinate system, or -1
	 * 
	 * @param coordSys
	 * @return coordNS_auto or -1 if not found
	 */
	public Integer getCoordinateSystemID(String coordSys){
		Set s = csmap.keySet();
		Iterator iter = s.iterator();
		while (iter.hasNext()){
			Integer key = (Integer) iter.next();
			COORDINATES ds = (COORDINATES)csmap.get(key);
			if (ds.toString().equals(coordSys)){
				return key;
			}
			
		}
		return new Integer(-1);
	}
	
	
	/** returns a DasCoordinateSystem, or null if it could not be found in the map
	 * 
	 * @param coordSys
	 * @return a DasCoordinateSystem or null
	 */
	public COORDINATES getCoordinateSystem (String coordSys) {
		
		Set s = csmap.keySet();
		Iterator iter = s.iterator();
		while (iter.hasNext()){
			Integer key = (Integer) iter.next();
			COORDINATES ds = (COORDINATES)csmap.get(key);
			if (ds.toString().equals(coordSys)){
				return ds;
			}
			
		}
		return null;
	}
	
	
	
	
	
	
	
	
	
	
}
